<?php
declare (strict_types=1);

namespace app\admin\controller;

use addons\BuilderPlus\components\Button;
use addons\BuilderPlus\components\Column;
use addons\BuilderPlus\components\Search;
use addons\BuilderPlus\facade\Table;
use app\common\model\Assets;
use app\common\tool\Result;
use think\Response;
use think\response\Json;

class Draw extends Base
{

    public function getOptions(): array
    {
        return [
            'pk'           => 'id',
            'model'        => \app\common\model\Draw::class,
            'with'         => ['user'],
            'append'       => ['statusText'],
            'memory_limit' => '1024M',
            'fast'         => [
                'edit'  => 'draw/edit',
                'save'  => '_save',
                'batch' => 'batch'
            ]
        ];
    }

    public function index(): string
    {
        return Table::init($this)
            ->addColumns([
                ['id', 'ID', fn(Column $col) => $col->width(80)],
                ['uid', '相关会员', fn(Column $col) => $col->minWidth(250)->templet('#_userTpl')],
                ['amount', '申请金额'],
                ['account', '提现账户'],
                ['mode', '提现方式'],
                ['money', '提现金额'],
                ['cost', '手续费'],
                ['amount', '实际金额'],
                ['create_time', '申请时间', fn(Column $col) => $col->width(140)],
                ['admin_name', '审核人'],
                ['confirm_time', '审核时间', fn(Column $col) => $col->width(140)],
                ['status', '状态', fn(Column $col) => $col->fixed('right')->templet('{{d.statusText}}')]
            ])
            ->addTopButtons(['batch'])
            ->addRightButtons(['edit' => fn(Button $btn) => $btn
                    ->class("{{ d.status == 1 ? 'danger' : 'normal' }}")
                    ->title("{{ d.status == 1 ? '审核' : '查看' }}")]
                , 90)
            ->addSearch([
                ['create_time', '提现时间', fn(Search $search) => $search->type('date')->dateType('datetime')],
                ['uid', '会员编号/昵称/手机号', fn($s) => $s->relation('\app\common\model\User', 'code|nickname|mobile,id')],
                ['account', '账户类型', fn($s) => $s->type('select')->optionValue(Assets::getFields(3))],
                ['status', '状态', fn($s) => $s->type('select')->optionValue([1 => '待审核', 2 => '已通过', 3 => '已驳回'])]
            ])
            ->enableExport()
            ->fetch();
    }
}
